package cn.signalpha.modules.base.service;

import cn.signalpha.core.mp.base.BaseServiceImpl;
import cn.signalpha.modules.base.entity.Bulletin;
import cn.signalpha.modules.base.mapper.BulletinMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.signalpha.common.cache.CacheNames.*;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class BulletinService extends BaseServiceImpl<BulletinMapper, Bulletin> {

	@Cacheable(cacheNames = BULLETIN_KEY)
	public List<Bulletin> listCache() {
		LambdaQueryWrapper<Bulletin> queryWrapper = Wrappers.lambdaQuery();
		queryWrapper.select(Bulletin::getId, Bulletin::getTitle, Bulletin::getBrief);
		return list(queryWrapper.orderByDesc(Bulletin::getId).last("limit 5"));
	}

	@Cacheable(cacheNames = BULLETIN_KEY + EXPIRATION_TIME, key = "#id")
	public Bulletin getByCache(Long id) {
		return getById(id);
	}

	@CacheEvict(cacheNames = BULLETIN_KEY, allEntries = true)
	public void removeCaChe() {
	}


}

